//
//  LS_HeaderView.m
//  App_6.23
//
//  Created by 芦珊 on 16/6/30.
//  Copyright © 2016年 lushan. All rights reserved.
//

#import "LS_HeaderView.h"

@interface LS_HeaderView ()

@property (nonatomic, strong) UIButton *button;


@end

@implementation LS_HeaderView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
       
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
    
}

- (void)createHeadView:(NSString *)name price:(NSString *)price nick:(NSString *)nick{
    
    
    for (UIView *view in self.subviews) {
        
        [view removeFromSuperview];
    }
    UIImage *image = [UIImage imageNamed:@"personal_background.jpg"];
    //原图
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT/4+20)];
    self.imageView.image = image;
    //self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.imageView];
    
    //用户头像图
    self.imageTitle = [[UIImageView alloc]init];
    self.imageTitle.layer.cornerRadius = 80 / 2.f;
    self.imageTitle.layer.borderWidth = 2;
    self.imageTitle.layer.borderColor = [UIColor whiteColor].CGColor;
    self.imageTitle.clipsToBounds = YES;
    [self.imageTitle sd_setImageWithURL:[NSURL URLWithString:nick] placeholderImage:PLACEHOLDER_CELL_SAME];
    [self addSubview:self.imageTitle];
    
    //添加tap
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pickeImage)];
    [self.imageTitle addGestureRecognizer:tap];
    //打开交互
    self.imageTitle.userInteractionEnabled = YES;

    [self.imageTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(@(15));
        make.bottom.equalTo(self.imageView.mas_bottom).offset(20);
        make.width.height.mas_equalTo(@80);
        
    }];
    
    self.nameL = [UILabel new];
    _nameL.textColor = [UIColor whiteColor];
    self.nameL.text = name;
    [self addSubview:_nameL];
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.imageTitle.mas_right).offset(10);
        make.top.equalTo(self.imageTitle);
        make.right.equalTo(@-20);
        make.height.equalTo(@40);
    }];
    
    UILabel *yuLabel = [UILabel new];
    [self addSubview:yuLabel];
    if (price.length == 0) {
        
        yuLabel.text = [NSString stringWithFormat:@"余额:  %@",@"0"];

    }else{
        
        yuLabel.text = [NSString stringWithFormat:@"余额:  %@",price];

    }
    [WH_AppTools changeColor:yuLabel.text color:[UIColor redColor] xx:price nn:yuLabel];
    [yuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.imageTitle.mas_right);
        make.top.equalTo(self.imageView.mas_bottom).offset(5);
        make.width.mas_equalTo(@120);
        make.height.equalTo(@30);
    }];
    
    UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    rechargeBtn.backgroundColor = [UIColor redColor];
    [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
    [rechargeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rechargeBtn.backgroundColor = [UIColor redColor];
    rechargeBtn.layer.cornerRadius = 3;
    rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:12.f];
    [rechargeBtn addTarget:self action:@selector(rechargeAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rechargeBtn];
    [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yuLabel);
        make.left.equalTo(yuLabel.mas_right);
        make.width.equalTo(@50);
        make.height.equalTo(@20);
    }];
    
}
#pragma mark -充值按钮响应方法
- (void)rechargeAction:(UIButton *)btn{
    
    [self.delegate pushtoRechargVC];
    NSLog(@"充值");
}

-(void)pickeImage{
    
    [self.delegate pushToView];
}

@end
